import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '../views/Home.vue'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes:[
        { path: '/', redirect: '/login'},
        { path: '/Home', redirect: '/Home/manual'},
        { path: '/Home',  name: 'Home', meta: {title: '主页'}, component: () => import('../views/Home.vue'),
            children: [
                { path: 'manual', name: 'manual', meta: { title: '使用说明'}, component: () => import('../views/manual.vue')},
                { path: 'CarInformation', name: 'InFormation', meta: { title: '信息'},component: () => import('../views/CarInformation.vue')},
                { path: 'runCar', name: 'Car', meta: { title: '发布拼车'},component: () => import('../views/runCar.vue')},
                { path: 'Person', name: 'person', meta: { title: '个人信息'},component: () => import('../views/person.vue')},
                { path: 'History', name: 'history', meta: { title: '历史'},component: () => import('../views/history.vue')},
            ]},
        { path: '/register', name: 'register', meta: {title: '注册'},component: () => import('../views/register.vue')},
        { path: '/login', name: 'login', meta: {title: '登录'},component: () => import('../views/login.vue')},
        { path: '/404', name: 'NotFound', meta: { title: '404找不到界面'},component: () => import('../views/404.vue')},
        { path: '/:pathMatch(.*)', redirect: '/404'},
  ]
})

router.beforeEach((to,from,next) =>{
  document.title = to.meta.title
  next()
})

export default router
